package com.yuan.springcloud.autoimport;

import com.yuan.springcloud.autoimport.annotation.EnableAutoImportBean;
import com.yuan.springcloud.autoimport.bean.AutoImportBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.util.Assert;

import java.util.Objects;

/**
 * @author YouYuan
 * @date 2020/8/17 23:46
 */
@EnableAutoImportBean
public class AutoImportApplication {

    public static void main(String[] args) {
        //获取spring容器
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AutoImportApplication.class);
        /**
         * 自动获取Bean流程:
         * 1. 读取到注解@EnableAutoImportBean
         * 2. BeanImportSelector.class告诉Spring加载指定的配置类（ImportSelector还会加载MATE-INF下spring.factories文件指定的类）
         * 3. 加载AutoImportBeanConfiguration.class配置类
         * 4. Spring初始化Bean放入容器
         */
        AutoImportBean bean = ac.getBean(AutoImportBean.class);
        System.out.println(bean);
        Assert.notNull(bean, "自动导入bean失败");
        Assert.isTrue(Objects.equals(bean.getId(), 126), "bean属性注入出错");
    }
}
